<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use app\admin\model\PurchaseModel;
use app\admin\validate\PurchaseValidate;
class Purchase extends Common
{
    //采购列表
    public function index()
    {
        $status =request()->param('status');
        $startime =request()->param('startime');
        $endtime =request()->param('endtime');
        $supplier =request()->param('supplier');
        $warehouse =request()->param('warehouse');
        $number =request()->param('number');
        $startime =strtotime($startime);
        $endtime =strtotime($endtime);
        $model =new PurchaseModel();
        $list =$model->getList($status,$startime,$endtime,$supplier,$warehouse,$number);
        //print_r($list);die;
        if(!empty($list)){
            return json(['code'=>200,'msg'=>'成功','list'=>$list]);
        }else{
            return json(['code'=>404,'msg'=>'失败']);
        }
    }
    //采购单新增
    public function add()
    {
        $data['create_time'] =request()->param('create_time');//采购日期
        $data['supplier'] =request()->param('supplier');//供应商
        $data['warehouse'] =request()->param('warehouse');//仓库
        $data['goods_id'] =request()->param('goods_id');//商品id
        $data['set_account'] =request()->param('set_account');//结算账户
        $data['payment'] =request()->param('payment');//实付金额
        $data['owe_payment'] =request()->param('owe_payment');//欠供应商款
        $data['remarks'] =request()->param('remarks');//备注
        $data['enclosure'] =request()->param('enclosure');//附件
        $data['total'] =request()->param('total');//合计
        $validate =new PurchaseValidate();
        if (!$validate->check($data)) {
            return json(['code'=>404,'msg'=>$validate->getError()]);
        }
        $model =new PurchaseModel();
        $arr =$model->getAdd($data);
        if(!empty($arr)){
            return json(['code'=>200,'msg'=>'添加成功']);
        }else{
            return json(['code'=>404,'msg'=>'添加失败']);
        }
    }
}